//
//  HsLCSexChooseView.m
//  TestIos
//
//  Created by hs on 2020/11/4.
//  Copyright © 2020 Liyadong. All rights reserved.
//

#import "HsLCSexChooseView.h"
#import "UIColor+Extend.h"
#import "Masonry.h"

@interface HsLCSexChooseView ()

/** btn0 */
@property (nonatomic, strong) UIButton *btn0;

/** btn2 */
@property (nonatomic, strong) UIButton *btn1;

/** btn3 */
@property (nonatomic, strong) UIButton *btn2;


@end


@implementation HsLCSexChooseView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        [self addSubview:self.btn0];
        UILabel *line1 = [self createLine];
        [self addSubview:line1];
        [self addSubview:self.btn1];
        UILabel *line2 = [self createLine];
        [self addSubview:line2];
        [self addSubview:self.btn2];
        
        [self.btn0 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.mas_equalTo(0);
            make.height.mas_equalTo(HsLCSexChooseView_item_H);
        }];
      
        [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.btn0.mas_bottom);
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(HsLCSexChooseView_line_H);
        }];
        
        [self.btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(line1.mas_bottom);
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(HsLCSexChooseView_item_H);
        }];
        
        [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.btn1.mas_bottom);
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(HsLCSexChooseView_line_H);
        }];
       
        [self.btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(line2.mas_bottom);
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(HsLCSexChooseView_special_item_H);
        }];
        
    }
    return self;
}

- (HsLCSexChooseView *)createChooseView {
    CGRect frame = CGRectMake(0, 0, MAIN_SCREEN_WIDTH, HsLCSexChooseView_H);
    HsLCSexChooseView *chooseView = [[HsLCSexChooseView alloc] initWithFrame:frame];
    
    return chooseView;
}

- (UIButton *)btn0 {
    if (!_btn0) {
        _btn0 = [self createBtnWithTitleStr:@"男" Index:0];
        [_btn0 addTarget:self action:@selector(handl0:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn0;
}
- (UIButton *)btn1 {
    if (!_btn1) {
        _btn1 = [self createBtnWithTitleStr:@"女" Index:1];
        [_btn1 addTarget:self action:@selector(handl1:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn1;
}
- (UIButton *)btn2 {
    if (!_btn2) {
        _btn2 = [self createBtnWithTitleStr:@"取消" Index:2];
        [_btn2 addTarget:self action:@selector(handl2:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _btn2;
}


- (UIButton *)createBtnWithTitleStr:(NSString *)titleStr Index:(NSInteger)index {
    UIButton *tempBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [tempBtn setTitle:titleStr forState:UIControlStateNormal];
    UIFont *font = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular];
    tempBtn.titleLabel.font = font;
    [tempBtn setTitleColor:[UIColor colorWithHexString:@"#2A2B30"] forState:UIControlStateNormal];
    return tempBtn;
}


- (UILabel *)createLine {
    UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    tempLabel.backgroundColor = [UIColor colorWithHexString:@"#F7F7F9"];
    return tempLabel;
}

- (void)handl0:(id)sender {
    if (self.clickAction) {
        self.clickAction(1);
    }
}
- (void)handl1:(id)sender {
    if (self.clickAction) {
        self.clickAction(2);
    }
}
- (void)handl2:(id)sender {
    if (self.clickAction) {
        self.clickAction(0);
    }
}

//1 选择男，2 选中女 其它都不选中
- (void)updateChooseWithIndex:(NSInteger)index {
    UIColor *unSelectColor = [UIColor colorWithHexString:@"#2A2B30"];
    UIColor *selectColor = [UIColor colorWithHexString:@"#EF4034"];

    if (index == 1) {
        [self.btn0 setTitleColor:selectColor forState:UIControlStateNormal];
        [self.btn1 setTitleColor:unSelectColor forState:UIControlStateNormal];

    } else if (index == 2) {
        [self.btn0 setTitleColor:unSelectColor forState:UIControlStateNormal];
        [self.btn1 setTitleColor:selectColor forState:UIControlStateNormal];
    } else {
        [self.btn0 setTitleColor:unSelectColor forState:UIControlStateNormal];
        [self.btn1 setTitleColor:unSelectColor forState:UIControlStateNormal];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
